
package org.codebase.spring.framework.aop.annotation;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 切面
 * *************************************************
 * ClassName:Audience
 * *************************************************
 */
@Aspect
@Component
public class Audience {

    //切点表达式
    @Pointcut("execution(** org.codebase.spring.framework.aop.Performance.perform(..))")
    public void performance() {
    }

    @Pointcut(
            "execution(** org.codebase.spring.framework.aop.Performance.performHasArgs(String))" +
                    "&& args(arg)"
    )
    public void performHasArgs(String arg) {

    }

    @Pointcut(
            "execution(** org.codebase.spring.framework.aop.annotation.NotInterfaceClass.performHasArgs(String))" +
                    "&& args(arg)"
    )
    public void notInterfaceClassHasArgs(String arg) {
    }

    //===================NotInterfaceClassHasArgs==================
    @Before("notInterfaceClassHasArgs(arg)")
    public void notInterfaceClassHasArgsBefore(String arg) {
        System.out.println("notInterfaceClassHasArgsBefore.arg.{" + arg + "}");
    }
    //===================performHasArgs==================

    @Before("performHasArgs(arg)")
    public void performHasArgsBefore(String arg) {
        System.out.println("performHasArgsBefore.arg.{" + arg + "}");
    }

    //===================performance==================
    @Before("performance()")
    public void silenceCellPhones() {
        System.out.println("silenceCellPhones1");
    }

    @Before("performance()")
    public void takeSeats() {
        System.out.println("takeSeats");
    }

    @AfterReturning("performance()")
    public void applause() {
        System.out.println("applause");
    }

    @AfterThrowing("performance()")
    public void demandRefund() {
        System.out.println("demandRefund");
    }
}
